// client.cpp
#include "NamedPipe.h"
#include <string>
#include <thread>
#include <chrono>

void reader(NamedPipe &pipe, bool *isExit) {
    while (!(*isExit)) {
        std::string received = pipe.read();
        std::cout << "Service received: " << received << std::endl;

		if (received == "exit")
		{

			std::cout << "!!!!!!!!!!!";
			break;
		}
    }
}

void writer(NamedPipe &pipe, bool *isExit) {
    while (!(*isExit)) {
        std::string message;
        std::getline(std::cin, message);
		pipe.write(message);
    }
}



int main() {
    NamedPipe serverPipe("/tmp/server_pipe");
    NamedPipe clientPipe("/tmp/client_pipe");

//	bool isExit = false;

//	std::thread readerThread(reader, std::ref(clientPipe), &isExit);
//	std::thread writerThread(writer, std::ref(serverPipe), &isExit);
	
//	readerThread.join();
//	writerThread.join();

    while (true) {
        std::string message = serverPipe.read();
        if (!message.empty()) {
            std::cout << "cmd from server: " << message << std::endl;
//
//            // 回应客户端
//            std::string response = "Server received: " + message;
            serverPipe.write("reveice and response");
        }
    }
    return 0;
}


